package edu.gyc.hishiro.controller;


import edu.gyc.hishiro.model.Student;
import edu.gyc.hishiro.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author ls
 * @since 2021-01-04
 */
@Controller
@Slf4j
@RequestMapping("/stu")
public class StudentController {
    @Autowired
    private StudentService studentService;

//    @RequiresPermissions("stu:add")
    @RequestMapping("/add")
    public String addStu(Model model) {
        log.info("called add student.");
        return "admin/student";
    }

//    @RequiresPermissions("stu:del")
    @RequestMapping("/del")
    public String delStu(Model model) {
        log.info("called del student.");
        return "admin/student";
    }

//    @RequiresPermissions("stu:update")
    @RequestMapping("/update")
    public String updateStu(Model model) {
        log.info("called update student.");
        return "admin/student";
    }

//    @RequiresPermissions("stu:query")
    @RequestMapping("/query")
    public String queryStu(Model model) {
//        log.info("called update student.");
        List<Student> students = studentService.lambdaQuery().orderByDesc(Student::getBirthday).list();
        model.addAttribute("stus", students);
        return "admin/student";
    }

    @RequestMapping("/test")
    public String test(Model model) {
        Student student=studentService.findById(1);
        log.info(studentService.findById(1).toString());

        student.setName("赵玉洁");
        studentService.update(student);
        return "admin/student";
    }

}

